<template>
	<div class="user-account">
		<div class="com-header border-1px">
			<div class="back"
				onclick="javascript:history.go(-1)"
			>
				<i class="iconfont">&#xe697;</i>
			</div>
			<div class="content">
				绑定支付宝账号
			</div>
		</div>
		<div class="uc-content">
			<div class="uc-name border-1px">
				<input type="text"
					v-model.trim="realname" 
					placeholder="输入支付宝姓名">
			</div>
			<div class="uc-name border-1px">
				<input type="text"
					v-model.trim="withdraw_to"  
					placeholder="输入支付宝账号">
			</div>
			<div class="uc-name border-1px">
				<input type="text"
				 	v-model.trim="smsCode"
					placeholder="请输入验证码">
				<p class="uc-btn" @click="getCode()">{{verifyText}}</p>
			</div>
			<div class="uc-submit"
				@click="submit()"
			>完成</div>
			<div class="uc-tip">
				注：请仔细核对用户信息
			</div>
		</div>
	</div>
</template>
<script>
	import { Toast } from 'mint-ui'
	import axios from 'axios'
	import Http from '../http.js'
	export default{
		data(){
			return{
				verifyText: '获取验证码',
				realname: '',
				withdraw_to: '',
				smsCode: ''
			}
		},
		methods: {
			submit: function(){
				var params = new URLSearchParams();
                params.append('realname', this.realname);
                params.append('withdraw_to', this.withdraw_to);
                params.append('smsCode', this.smsCode);
                axios.post(Http.ALIPAYACCOUNTBIND, params).then( res => {
                	var ret =res.data;
                	var recode = ret['code']
                	if(recode === 1){
                		Toast(ret['msg']);
                		this.$router.go(-1);
                	}else{
                		Toast(ret['msg'])
                	}
                })
			},
			getCode: function (event) {
	            if (this.mobile === '') {
	                Toast('请先输入手机号码')
	                return
	            }
	            this.isSending = true;
	            var params = new URLSearchParams();
                params.append('mobile', this.withdraw_to);
                params.append('event', 'withdraw');
	            axios.post(Http.SMSSEND, params)
	                .then( res => {
	                    const ret = res.data
	                    if (ret['code'] === 1) {
	                        let count = 60;
	                        Toast('短信已发送');
	                        let tempObject = setInterval(() => {
	                            this.verifyText = count--;
	                            if (count <= 0) {
	                                this.isSending = false
	                                this.verifyText = '重新获取'
	                                clearInterval(tempObject)
	                            }
	                        }, 1000);
	                    } else {
	                        Toast(ret['msg'])
	                        this.isSending = false
	                    }
	                }, (res) => {
	                    this.isSending = false
	                })
		    },
		}
	}
</script>
<style lang="scss" scoped>
	.user-account{
		.uc-content{
			min-height: 11.8rem;
			background: #f5f5f5;
			padding-top: 0.2rem;
			.uc-name{
				margin: 0 0.24rem;
				position: relative;
				input{
					width: 100%;
					text-indent: 0.3rem;
					height: 1.2rem;
					background: #fff;
				}
				p{
					position: absolute;
					top: 0.2rem;
					right: 0.24rem;
					width: 2rem;
					height: 0.8rem;
					line-height: 0.8rem;
					border-radius: 0.1rem;
					border: 0.01rem solid #e4e7ed;
				}
			}
			.uc-submit{
				margin: 0 0.24rem;
				margin-top: 0.4rem;
				height: 1rem;
				line-height: 1rem;
				background: #fff;
				font-size: 0.30rem;
				color: #1aaceb;
			}
			.uc-tip{
				margin-top: 0.2rem;
			}
		}
	}
</style>